package org.demo.filemanager.widget.xml;

import org.boxlayout.gui.BoxLayoutEngine;
import org.boxlayout.gui.VisualElement;
import org.boxlayout.gui.layout.LayoutFactory;
import org.boxlayout.gui.type.ColorEnum;
import org.boxlayout.gui.widget.TreeBrowsable;
import org.demo.filemanager.Selector;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class XmlElementWidget extends XmlNodeWidget{

	Element element ;
	
	public XmlElementWidget(BoxLayoutEngine ble, Selector selector, Node node) {
		super(ble, node);
		name = node.getNodeName();
		this.element = (Element)node;
	}
	
	public TreeBrowsable initVisual() {
		//System.out.println("FileWidget init begin");
		color = defaultColor;
		nameContainer = ble.createElement()
		.setColor(color).setColor2(ColorEnum.LIGHTGRAY)
		.setPadding(0.05f).setText(name)
		.setId(name.hashCode());
		
		VisualElement attrsContainer = ble.createElement().setLayout(LayoutFactory.getInstance().getVerticalLayout())
		.setPadding(0.00f).setColor(ColorEnum.WHITE);
		
		NamedNodeMap attributes = element.getAttributes();
		for(Integer i = 0,n = attributes.getLength();i<n;i++){
			Node attr = (Node)attributes.item(i);
			attrsContainer.add(new XmlAttributeWidget(ble,attr.getNodeName(),attr.getNodeValue()).initVisual().getVisual());
			
		}
		
		VisualElement barContainer = ble.createElement().setLayout(LayoutFactory.getInstance().getHorizontalLayout())
		.setPadding(0.00f).setColor(ColorEnum.WHITE).add(nameContainer).add(attrsContainer);
		
		
		
		
		visual = ble.createElement().setLayout(LayoutFactory.getInstance().getVerticalLayout())
		.setPadding(0.00f).setColor(ColorEnum.WHITE);
		visual.add(barContainer);
		//System.out.println("FileWidget init end");
		return this;
	}

}
